class TreeNode:
    def __init__(self, x=0):
        self.val = x
        self.left = None
        self.right = None


def is_binary_search_tree(root: TreeNode):
    """
    判断是否二分查找树， node.left.val < node,val < node.right.val
    :param root:
    :return:
    """
    if not root:
        return False
    lst = []

    def process(root: TreeNode):
        if not root:
            return
        process(root.left)
        lst.append(root.val)
        process(root.right)

    process(root)
    for i in range(1, len(lst)):
        if lst[i] <= lst[i - 1]:
            return False
    return True


if __name__ == "__main__":
    head = TreeNode(6)
    head.left = TreeNode(3)
    head.left.left = TreeNode(1)
    head.left.left.right = TreeNode(2)
    head.left.right = TreeNode(4)
    head.left.right.right = TreeNode(5)
    head.right = TreeNode(9)
    head.right.left = TreeNode(8)
    head.right.left.left = TreeNode(7)
    head.right.right = TreeNode(10)
    print(is_binary_search_tree(head))
    